{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "gpuClass": "standard"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Roboflow 100 📸: A Rich, Multi-Domain Object Detection Benchmark"
      ],
      "metadata": {
        "id": "g2uod8gl8sw9"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "![rf100blog-mosaicthing](https://user-images.githubusercontent.com/15908060/202452898-9ca6b8f7-4805-4e8e-949a-6e080d7b94d2.jpg)\n",
        "\n",
        "This repository implements the Roboflow 100 benchmark developed by [Roboflow](https://roboflow.com/). It contains code to download the dataset and reproduce\n",
        "mAP values for YOLOv5 and YOLOv7 Fine-Tuning and GLIP Evaluation on 100 of Roboflow Universe\n",
        "datasets.\n",
        "\n",
        "\n",
        "*RF100 was sponsored with ❤️ by [Intel](https://www.intel.com/content/www/us/en/homepage.html)*\n"
      ],
      "metadata": {
        "id": "uOclgVqDdjQ1"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## RF100\n",
        "\n",
        "`RF100` contains the following datasets, carefully chosen from more than 90'000 datasets hosted on our [universe hub](https://universe.roboflow.com/). The datasets are splitted in 7 categories: `Aerial`, `Videogames`, `Microscopic`, `Underwater`, `Documents`, `Electromagnetic` and `Real World`. \n",
        "\n",
        "\n",
        "| Category        | Datasets | Images  | Classes |\n",
        "|-----------------|----------|---------|---------|\n",
        "| Aerial          | 7        | 9683    | 24      |\n",
        "| Videogames      | 7        | 11579   | 88      |\n",
        "| Microscopic     | 11       | 13378   | 28      |\n",
        "| Underwater      | 5        | 18003   | 39      |\n",
        "| Documents       | 8        | 24813   | 90      |\n",
        "| Electromagnetic | 12       | 36381   | 41      |\n",
        "| Real World      | 50       | 110615  | 495     |\n",
        "| **Total**           | **100**      | **224,714** | **805**     |"
      ],
      "metadata": {
        "id": "xY-4vI8FdyGc"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## confirm GPU access"
      ],
      "metadata": {
        "id": "sK8OgCt-LbA2"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!nvidia-smi"
      ],
      "metadata": {
        "id": "9SvyGlrfLiBy"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## set ROBOFLOW_API_KEY"
      ],
      "metadata": {
        "id": "qY7YhaW1CKkN"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%env ROBOFLOW_API_KEY=<YOUR_API_KEY>"
      ],
      "metadata": {
        "id": "IdONEiqcCIPr"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## pull RF100 repository"
      ],
      "metadata": {
        "id": "jzxHbHvrdzgm"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%cd /content/\n",
        "!rm -rf roboflow-100-benchmark/\n",
        "!git clone https://github.com/roboflow-ai/roboflow-100-benchmark.git\n",
        "\n",
        "%cd /content/roboflow-100-benchmark/\n",
        "!git submodule update --init --recursive\n",
        "\n",
        "!pip install roboflow --quiet"
      ],
      "metadata": {
        "id": "e2QDKnEE96Ya"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!ls -la"
      ],
      "metadata": {
        "id": "p3Mc4RykKFVE"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Download all datasets"
      ],
      "metadata": {
        "id": "LgcYCeg6Ic2E"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# !rm -rf /content/datasets/\n",
        "# !scripts/download_datasets.sh -f yolov5 -l /content/datasets/"
      ],
      "metadata": {
        "id": "xcGkf6Z-fXn-"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Download selected dataset"
      ],
      "metadata": {
        "id": "mPffiS6gIixw"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!head -n 10 datasets_links_640.txt"
      ],
      "metadata": {
        "id": "ZGODXhNIDNz6"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!rm -rf /content/datasets/\n",
        "!python scripts/download_dataset.py -p x-ray-rheumatology -v 2 -f yolov5 -l /content/datasets/"
      ],
      "metadata": {
        "id": "r_Z67zntInq9"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!ls /content/datasets/x-ray-rheumatology"
      ],
      "metadata": {
        "id": "Xpd6U62fJxWo"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "dataset=\"/content/datasets/x-ray-rheumatology\""
      ],
      "metadata": {
        "id": "5AmxaCrdcfZo"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Setup YOLOv7 training environment"
      ],
      "metadata": {
        "id": "kj5yXfvNKOTq"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%cd /content/roboflow-100-benchmark/yolov7-benchmark/yolov7/\n",
        "!wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7_training.pt"
      ],
      "metadata": {
        "id": "vq4nbSwLJ6JQ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!python train.py --img 640 --batch 8 --epochs 100 --name $dataset/results --data $dataset/data.yaml  --weights 'yolov7_training.pt' |& tee $dataset/logs.txt "
      ],
      "metadata": {
        "id": "UDSV4LZObjuD"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!python test.py --data $dataset/data.yaml --img 640 --batch 16 --weights $dataset/results/weights/best.pt --name  $dataset --exist-ok |& tee $dataset/val_eval.txt "
      ],
      "metadata": {
        "id": "5XU-A_-jdABA"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}